#!/bin/bash
# 备份脚本
export ANDROID_HOME=~/Library/Android/sdk

NEW_PACKAGE_NAME="com.linigyesdk.test" # 配置包名
NEW_APP_NAME="上海领页-测试" # 配置App名字
MANIFEST_PATH="app/src/main/AndroidManifest.xml"
STRINGS_PATH="app/src/main/res/values/strings.xml"


echo "ly_log_开始打包"
export LANG=en_US.UTF-8
echo "ly_log_切换到项目根目录"
cd H5AdNative

echo "ly_log_获取gradle权限"
chmod +x gradlew
echo "ly_log_clean"
./gradlew -s clean

echo "ly_log_修改包名和App名字"
sed -i '' "s/applicationId .*/applicationId \"$NEW_PACKAGE_NAME\"/g" app/build.gradle
sed -i '' "s/<string name=\"app_name\">[^<]*<\/string>/<string name=\"app_name\">$NEW_APP_NAME<\/string>/g" app/src/main/res/values/strings.xml
echo "ly_log_修改完成"

echo "ly_log_开始构建APK"
./gradlew -s assembleRelease -Pandroid.injected.signing.store.file=qbll.keystore -Pandroid.injected.signing.store.password=123456 -Pandroid.injected.signing.key.alias=qbll -Pandroid.injected.signing.key.password=123456

if [ $? -eq 0 ]; then

echo "ly_log_构建成功，准备上传蒲公英"
# 上传ipa到蒲公英
response=$(curl -F "file=@app/build/outputs/apk/release/app-release.apk" \  -F "uKey=56f85d8d72945ad91e84fc32831e0bc9" \     -F "_api_key=75c67f7a024ec6d6a3656fb48494e0f6" \     https://www.pgyer.com/apiv1/app/upload)
echo $response
baseUrl="https://www.pgyer.com/"
path=$(echo "$response" | jq -r '.data.appShortcutUrl')
echo "上传成功"
echo "SHA1值： 2D:72:BE:61:02:92:3E:81:B5:8A:80:2E:5E:26:9B:FC:F6:61:C7:F1"
echo "下载地址为： $baseUrl$path"

else

echo "构建失败，请检查错误日志。"

exit 1
fi



